home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Source / GNU / cctools / as / messages.c < prev    next >
C/C++ Source or Header  |  1994-06-03  |  7KB  |  268 lines

  1. /* messages.c - error reporter -
  2.    Copyright (C) 1987 Free Software Foundation, Inc.
  3.  
  4. This file is part of GAS, the GNU Assembler.
  5.  
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GAS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GAS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include <stdarg.h>
  22. #include <streams/streams.h>
  23. #include "make.h"
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <mach/mach_init.h>
  27. #include <servers/netname.h>
  28. #include "as.h"
  29. #include "input-scrub.h"
  30. #include "messages.h"
  31.  
  32. /*
  33.         ERRORS
  34.  
  35.     We print the error message 1st, beginning in column 1.
  36.     All ancillary info starts in column 2 on lines after the
  37.     key error text.
  38.     We try to print a location in logical and physical file
  39.     just after the main error text.
  40.     Caller then prints any appendices after that, begining all
  41.     lines with at least 1 space.
  42.  
  43.     Optionally, we may die.
  44.     There is no need for a trailing '\n' in your error text format
  45.     because we supply one.
  46.  
  47. as_warn(fmt,args)  Like fprintf(stderr,fmt,args) but also call errwhere().
  48.  
  49. as_fatal(fmt,args) Like as_warn() but exit with a fatal status.
  50.  
  51. */
  52.  
  53.  
  54. /*
  55.  * Nonzero if we've hit a 'bad error', and should not write an obj file,
  56.  * and exit with a nonzero error code.
  57.  */
  58. int bad_error = 0;
  59.  
  60. /*
  61.  * If set to non-zero in main() -arch_multiple as been specified so if any
  62.  * error messages are printed print a single line first to start which errors
  63.  * the architectures are for.
  64.  */
  65. int arch_multiple = 0;
  66.  
  67. /*
  68.  * This is for the ProjectBuilder (formally MakeApp) interface.
  69.  */
  70. static int talking_to_ProjectBuilder = 0;
  71. static NXStream *ProjectBuilder_stream = NULL;
  72. static port_t ProjectBuilder_port;
  73.  
  74. /*
  75.  * check_for_ProjectBuilder() is called once before any error messages are
  76.  * generated and sets up what is needed to send error messages to project
  77.  * builder.
  78.  */
  79. void
  80. check_for_ProjectBuilder(void)
  81. {
  82.     char *portName, *hostName;
  83.     
  84.     portName = getenv("MAKEPORT");
  85.     hostName = getenv("MAKEHOST");
  86.     if(portName == NULL)
  87.         return;
  88.     if(hostName == NULL)
  89.         hostName = "";
  90.     if(netname_look_up(name_server_port, hostName, portName,
  91.        &ProjectBuilder_port) != KERN_SUCCESS)
  92.         return;
  93.     if(ProjectBuilder_port == PORT_NULL)
  94.         return;
  95.     if((ProjectBuilder_stream = NXOpenMemory(NULL, 0, NX_WRITEONLY)) ==
  96.        NULL)
  97.         return;
  98.     talking_to_ProjectBuilder = 1;
  99. }
  100.  
  101. /*
  102.  * tell_ProjectBuilder() takes the message in the stream and sends it to project
  103.  * builder.  It then resets the stream for the next message.
  104.  */
  105. static
  106. void
  107. tell_ProjectBuilder(
  108. int eventType) /* 0 error, 1 warning, -1 doing */
  109. {
  110.     char *fileName, *directory, *message;
  111.     int line, len, maxlen;
  112.  
  113.     as_where_ProjectBuilder(&fileName, &directory, &line);
  114.     if(fileName == NULL)
  115.         fileName = "";
  116.     if(directory == NULL)
  117.         directory = "";
  118.     NXGetMemoryBuffer(ProjectBuilder_stream, &message, &len, &maxlen);
  119.     make_alert(ProjectBuilder_port,
  120.         eventType,
  121.         NULL, 0, /* functionName, not used by ProjectBuilder */
  122.         fileName, strlen(fileName)+1 > 1024 ? 1024 : strlen(fileName)+1,
  123.         directory, strlen(directory)+1 > 1024 ? 1024 : strlen(directory)+1,
  124.         line,
  125.         message, len+1 > 1024 ? 1024 : len+1);
  126.     NXSeek(ProjectBuilder_stream, 0, NX_FROMSTART);
  127. }
  128.  
  129. /*
  130.  * architecture_banner() returns the string to say what target we are assembling
  131.  * for.
  132.  */
  133. static
  134. const char *
  135. architecture_banner(void)
  136. {
  137. #ifdef M68K
  138.     return("as: for architecture m68k\n");
  139. #endif
  140. #ifdef M88K
  141.     return("as: for architecture m88k\n");
  142. #endif
  143. #ifdef M98K
  144.     return("as: for architecture m98k\n");
  145. #endif
  146. #ifdef I860
  147.     return("as: for architecture i860\n");
  148. #endif
  149. #ifdef I386
  150.     return("as: for architecture i386\n");
  151. #endif
  152. #ifdef HPPA
  153.     return("as: for architecture hppa\n");
  154. #endif
  155. #ifdef SPARC
  156.     return("as: for architecture sparc\n");
  157. #endif
  158. }
  159.  
  160. /*
  161.  * print_architecture_banner() prints what architecture we are assembling for
  162.  * if it has not previously been printed.
  163.  */
  164. static
  165. void
  166. print_architecture_banner(void)
  167. {
  168.     static int printed = 0;
  169.  
  170.     if(arch_multiple && !printed){
  171.         printf(architecture_banner());
  172.         if(talking_to_ProjectBuilder)
  173.         NXPrintf(ProjectBuilder_stream, architecture_banner());
  174.         printed = 1;
  175.     }
  176. }
  177.  
  178. /*
  179.  *            a s _ w a r n ( )
  180.  *
  181.  * Send to stderr a string as a warning, and locate warning in input file(s).
  182.  * Please only use this for when we have some recovery action.
  183.  * Please explain in string (which may have '\n's) what recovery was done.
  184.  */
  185. void
  186. as_warn(
  187. const char *format,
  188. ...)
  189. {
  190.     va_list ap;
  191.  
  192.     if(!flagseen['W']){
  193.         print_architecture_banner();
  194.         bad_error = 1;
  195.         as_where();
  196.         va_start(ap, format);
  197.         vfprintf(stderr, format, ap);
  198.         fprintf(stderr, "\n");
  199.         if(talking_to_ProjectBuilder){
  200.         NXVPrintf(ProjectBuilder_stream, format, ap);
  201.         NXPrintf(ProjectBuilder_stream, "\n");
  202.         tell_ProjectBuilder(1 /* warning */);
  203.         }
  204.         va_end(ap);
  205.     }
  206. }
  207.  
  208. /*
  209.  *            a s _ b a d ( )
  210.  *
  211.  * Send to stderr a string as a warning, * and locate warning in input file(s).
  212.  * Please us when there is no recovery, but we want to continue processing
  213.  * but not produce an object file.
  214.  * Please explain in string (which may have '\n's) what recovery was done.
  215.  */
  216. void
  217. as_bad(
  218. const char *format,
  219. ...)
  220. {
  221.     va_list ap;
  222.  
  223.     print_architecture_banner();
  224.     bad_error = 1;
  225.     as_where();
  226.     va_start(ap, format);
  227.     vfprintf(stderr, format, ap);
  228.     fprintf(stderr, "\n");
  229.     if(talking_to_ProjectBuilder){
  230.         NXVPrintf(ProjectBuilder_stream, format, ap);
  231.         NXPrintf(ProjectBuilder_stream, "\n");
  232.         tell_ProjectBuilder(0 /* error */);
  233.     }
  234.     va_end(ap);
  235. }
  236.  
  237. /*
  238.  *            a s _ f a t a l ( )
  239.  *
  240.  * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a fatal
  241.  * message, and locate stdsource in input file(s).
  242.  * Please only use this for when we DON'T have some recovery action.
  243.  * It exit()s with a warning status.
  244.  */
  245. void
  246. as_fatal(
  247. const char *format,
  248. ...)
  249. {
  250.     va_list ap;
  251.  
  252.     print_architecture_banner();
  253.     bad_error = 1;
  254.     as_where();
  255.     va_start(ap, format);
  256.     fprintf (stderr, "FATAL:");
  257.     vfprintf(stderr, format, ap);
  258.     fprintf(stderr, "\n");
  259.     if(talking_to_ProjectBuilder){
  260.         NXPrintf(ProjectBuilder_stream, "FATAL:");
  261.         NXVPrintf(ProjectBuilder_stream, format, ap);
  262.         NXPrintf(ProjectBuilder_stream, "\n");
  263.         tell_ProjectBuilder(0 /* error */);
  264.     }
  265.     va_end(ap);
  266.     exit(1);
  267. }
  268.